package cn.tanglong.pay.controller;

import cn.tanglong.basic.exception.MyException;
import cn.tanglong.basic.util.AjaxResult;
import cn.tanglong.pay.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    // 发起支付申请
    @PostMapping("/applypay/{orderNo}")
    public AjaxResult applyPay(@PathVariable("orderNo")String orderNo){
        try {
            // 申请支付
            String htmlResult = payService.applyPay(orderNo);
            return AjaxResult.me().setResultObj(htmlResult);
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("pay接口失败！");
        }
    }
}
